home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / djet.c < prev    next >
C/C++ Source or Header  |  1993-06-18  |  25KB  |  953 lines

  1.  
  2.  
  3.    /*************************************************
  4.    *
  5.    *   file d:\cips\djet.c
  6.    *
  7.    *   Functions: This file contains
  8.    *      end_graphics_mode
  9.    *      get_graphics_caption
  10.    *      print_bytes
  11.    *      print_graphics_image
  12.    *      print_original_200_row
  13.    *      select_300_dpi_resolution
  14.    *      select_full_graphics_mode
  15.    *      set_horizontal_offset
  16.    *      set_raster_width
  17.    *      start_raster_graphics
  18.    *
  19.    *   Purpose:
  20.    *      These functions print a 200x200 image using
  21.    *      dithering to an HP DeskJet or compatable 
  22.    *      (Laserjet). This uses an 8x8 matrix which 
  23.    *      gives 64 shades of gray.
  24.    *
  25.    *   External Calls:
  26.    *          rtiff.c - read_tiff_image
  27.    *           hist.c - zero_histogram
  28.    *                    calculate_histogram
  29.    *                    perform_histogram_equalization
  30.    *
  31.    *
  32.    *   Modifications:
  33.    *      January 1991 - created
  34.    *      25 August 1991 - modified for use in the
  35.    *         C Image Processing System.
  36.    *
  37.     ZDDDDD?   ZDDDDD?
  38.     3     3   3     3   The function print_graphics_image
  39.     3     3   3     3   begins with 2 100x100 image arrays
  40.     3     3   3     3
  41.     3     3   3     3
  42.     @DDDDDY   @DDDDDY
  43.  
  44.     ZDDDDDDDDDDDDDDD?
  45.     3               3   It joins them into
  46.     3               3   1 100x200 image array
  47.     3               3
  48.     3               3
  49.     @DDDDDDDDDDDDDDDY
  50.  
  51.     ZDDDDDDDDDDDDDDD?
  52.     @DDDDDDDDDDDDDDDY
  53.     ZDDDDDDDDDDDDDDD?
  54.     @DDDDDDDDDDDDDDDY
  55.            .            It loops and creates
  56.            .            100 200 element image arrays
  57.            .
  58.     ZDDDDDDDDDDDDDDD?
  59.     @DDDDDDDDDDDDDDDY
  60.  
  61.  
  62.           The function print_original_200_row 
  63.           receives a 200 element array
  64.     ZBDDDDDDDDDDDDDDDDDDDDDDDDDDB?
  65.     @ADDDDDDDDDDDDDDDDDDDDDDDDDDAY
  66.  
  67.           This array is transformed into a 8x200 
  68.           array of characters called 'row'
  69.     ZDDDDDDDDD ... ~DDDDDDD?
  70.     CDDDDDDDDD ... ~DDDDDDD4
  71.     CDDDDDDDDD ... ~DDDDDDD4
  72.     CDDDDDDDDD ... ~DDDDDDD4
  73.     CDDDDDDDDD ... ~DDDDDDD4
  74.     CDDDDDDDDD ... ~DDDDDDD4
  75.     CDDDDDDDDD ... ~DDDDDDD4
  76.     CDDDDDDDDD ... ~DDDDDDD4
  77.     @DDDDDDDDD ... ~DDDDDDDY
  78.  
  79.           Each column of this array is a 1x8 character
  80.           array which is an 8-bit x 8-bit array
  81.     IMM;
  82.     :  :
  83.     HMM<
  84.           Each row of 'row' is passed to the funnction 
  85.           print_bytes for graphics printing
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.    ***************************************************/
  93.  
  94.  
  95. #include "cips.h"
  96.  
  97. #define ESCAPE 27
  98. #define FORMFEED  '\014'
  99.  
  100. short r[200];
  101.  
  102.  
  103.  
  104.       /*******************************************
  105.       *
  106.       *   The patterns array holds the rows to the
  107.       *   8x8 matrices used for printing
  108.       *   shades of gray.
  109.       *
  110.       ********************************************/
  111.  
  112. char patterns[64][8] =
  113.    { {255, 255, 255, 255, 255, 255, 255, 255},
  114.      {255, 255, 255, 255, 255, 255, 255, 127},
  115.      {255, 255, 255, 255, 255, 255, 255,  63},
  116.      {255, 255, 255, 255, 255, 255, 255,  31},
  117.      {255, 255, 255, 255, 255, 255, 255,  15},
  118.      {255, 255, 255, 255, 255, 255, 255,   7},
  119.      {255, 255, 255, 255, 255, 255, 255,   3},
  120.      {255, 255, 255, 255, 255, 255, 255,   1},
  121.      {255, 255, 255, 255, 255, 255, 255,   0},
  122.      {255, 255, 255, 255, 255, 255, 127,   0},
  123.      {255, 255, 255, 255, 255, 255,  63,   0},
  124.      {255, 255, 255, 255, 255, 255,  31,   0},
  125.      {255, 255, 255, 255, 255, 255,  15,   0},
  126.      {255, 255, 255, 255, 255, 255,   7,   0},
  127.      {255, 255, 255, 255, 255, 255,   3,   0},
  128.      {255, 255, 255, 255, 255, 255,   1,   0},
  129.      {255, 255, 255, 255, 255, 255,   0,   0},
  130.      {255, 255, 255, 255, 255, 127,   0,   0},
  131.      {255, 255, 255, 255, 255,  63,   0,   0},
  132.      {255, 255, 255, 255, 255,  31,   0,   0},
  133.      {255, 255, 255, 255, 255,  15,   0,   0},
  134.      {255, 255, 255, 255, 255,   7,   0,   0},
  135.      {255, 255, 255, 255, 255,   3,   0,   0},
  136.      {255, 255, 255, 255, 255,   1,   0,   0},
  137.      {255, 255, 255, 255, 255,   0,   0,   0},
  138.      {255, 255, 255, 255, 127,   0,   0,   0},
  139.      {255, 255, 255, 255,  63,   0,   0,   0},
  140.      {255, 255, 255, 255,  31,   0,   0,   0},
  141.      {255, 255, 255, 255,  15,   0,   0,   0},
  142.      {255, 255, 255, 255,   7,   0,   0,   0},
  143.      {255, 255, 255, 255,   3,   0,   0,   0},
  144.      {255, 255, 255, 255,   1,   0,   0,   0},
  145.      {255, 255, 255, 255,   0,   0,   0,   0},
  146.      {255, 255, 255, 127,   0,   0,   0,   0},
  147.      {255, 255, 255,  63,   0,   0,   0,   0},
  148.      {255, 255, 255,  31,   0,   0,   0,   0},
  149.      {255, 255, 255,  15,   0,   0,   0,   0},
  150.      {255, 255, 255,   7,   0,   0,   0,   0},
  151.      {255, 255, 255,   3,   0,   0,   0,   0},
  152.      {255, 255, 255,   1,   0,   0,   0,   0},
  153.      {255, 255, 255,   0,   0,   0,   0,   0},
  154.      {255, 255, 127,   0,   0,   0,   0,   0},
  155.      {255, 255,  63,   0,   0,   0,   0,   0},
  156.      {255, 255,  31,   0,   0,   0,   0,   0},
  157.      {255, 255,  15,   0,   0,   0,   0,   0},
  158.      {255, 255,   7,   0,   0,   0,   0,   0},
  159.      {255, 255,   3,   0,   0,   0,   0,   0},
  160.      {255, 255,   1,   0,   0,   0,   0,   0},
  161.      {255, 255,   0,   0,   0,   0,   0,   0},
  162.      {255, 127,   0,   0,   0,   0,   0,   0},
  163.      {255,  63,   0,   0,   0,   0,   0,   0},
  164.      {255,  31,   0,   0,   0,   0,   0,   0},
  165.      {255,  15,   0,   0,   0,   0,   0,   0},
  166.      {255,   7,   0,   0,   0,   0,   0,   0},
  167.      {255,   3,   0,   0,   0,   0,   0,   0},
  168.      {255,   1,   0,   0,   0,   0,   0,   0},
  169.      {255,   0,   0,   0,   0,   0,   0,   0},
  170.      {127,   0,   0,   0,   0,   0,   0,   0},
  171.      { 63,   0,   0,   0,   0,   0,   0,   0},
  172.      { 31,   0,   0,   0,   0,   0,   0,   0},
  173.      { 15,   0,   0,   0,   0,   0,   0,   0},
  174.      {  7,   0,   0,   0,   0,   0,   0,   0},
  175.      {  3,   0,   0,   0,   0,   0,   0,   0},
  176.      {  1,   0,   0,   0,   0,   0,   0,   0}};
  177.  
  178.  
  179.  
  180.    /************************************************
  181.    *
  182.    *   print_graphics_image(...
  183.    *
  184.    ************************************************/
  185.  
  186. print_graphics_image(image1, image2, image_name,
  187.                      il, ie, ll, le, image_colors,
  188.                      invert, caption, show_hist,
  189.                      color_transform)
  190.    char  caption[], image_name[], color_transform[];
  191.    int   image_colors, invert,
  192.          il, ie, ll, le, show_hist;
  193.    short image1[ROWS][COLS], image2[ROWS][COLS];
  194. {
  195.    char c[80],
  196.         page[80];
  197.  
  198.    FILE *printer;
  199.  
  200.    int  i,
  201.         j;
  202.  
  203.    unsigned long histogram[256], final_hist[256];
  204.    printer = fopen("prn", "w");
  205.  
  206.  
  207.       /**********************************************
  208.       *
  209.       *   Print a few blank lines on the page.
  210.       *
  211.       ***********************************************/
  212.  
  213.    strcpy(page, "                             \n");
  214.    fputs(page, printer);
  215.    fputs(page, printer);
  216.  
  217.  
  218.       /***********************************************
  219.       *
  220.       *   Read in two image arrays.
  221.       *
  222.       ************************************************/
  223.  
  224.    printf("\nReading image");
  225.    read_tiff_image(image_name, image1, il, ie, ll, le);
  226.  
  227.  
  228.    printf("\nReading image");
  229.    read_tiff_image(image_name, image2, 
  230.                    il, ie+100, ll, le+100);
  231.  
  232.  
  233.       /**********************************************
  234.       *
  235.       *   If show_hist is 1 OR do hist equalization
  236.       *   then zero the histogram and
  237.       *   calculate it for the two image arrays.
  238.       *
  239.       ***********************************************/
  240.  
  241.    if( (show_hist == 1)  ||
  242.        (color_transform[0] == 'H')){
  243.       zero_histogram(histogram);
  244.       zero_histogram(final_hist);
  245.       printf("\nDJET> Calculating histograms");
  246.       calculate_histogram(image1, histogram);
  247.       calculate_histogram(image2, histogram);
  248.    }
  249.  
  250.         /*********************************************
  251.         *
  252.         *   Alter the images to 64 gray shades.
  253.         *   Either do it with straight multiply
  254.         *   and divide or use hist equalization.
  255.         *
  256.         *   If using hist equalization then you must
  257.